package blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.service.TagService;

import blog.entity.Tag;
import blog.mapper.TagMapper;
@Service
public class TagServiceImpl implements TagService{
	@Autowired
	private TagMapper tagMapper;
	
	public List<Tag> listTag() {
		//查询所有标签信息
		List<Tag> tagList = tagMapper.listTag();
		//查询标签对应的文章数量
		for (Tag tag : tagList) {
			Integer articleCount = tagMapper.getArticleCount(tag.getTagId());
			tag.setArticleCount(articleCount);
		}
		return tagList;
	}

	@Override
	public int addTag(Tag tag) {
		return tagMapper.addTag(tag);
	}

	@Override
	public int deleteTag(Integer tagId) {
		return tagMapper.deleteTag(tagId);
	}

	@Override
	public Tag getTagById(Integer tagId) {
		return tagMapper.getTagById(tagId);
	}

	@Override
	public int editTag(Tag tag) {
		
		return tagMapper.editTag(tag);
	}
}
